/*
 * These files are distributed under the terms of the GNU GPLv2, the GNU General
 * Public version 2. See LICENSE.txt
 */
package fileCommodore.plugin.pathChanger;

import java.awt.event.*;

import org.apache.commons.vfs.*;

import fileCommodore.plugin.*;

/**
 * @author nado18@gmail.com, on Aug 1, 2007
 */
public class PathChangerPlugin extends Plugin
{
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see fileCommodore.plugin.Plugin#activeSelectionChanged()
	 */
	@Override
	public void activeSelectionChanged()
	{
		// TODO Auto-generated method stub
		
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see fileCommodore.plugin.Plugin#handle(java.awt.event.KeyEvent)
	 */
	@Override
	public void handle( KeyEvent ev )
	{
		if (KeyEvent.VK_G == ev.getKeyCode() && isAltDown( ev ))
		{
			String path =
					ask(
						"Path to Change To",
						"Please enter the path you'd like to change to." );
			
			if (null != path)
			{
				try
				{
					FileObject foTo =
							getActiveSelection().getCurrent().getFileObject().resolveFile(
								path );
					
					if (!foTo.exists())
					{
						showWarning(
							"Path Changer",
							"The specified path does not exist!" );
					}
					else if (foTo.getType() != FileType.FOLDER)
					{
						showWarning(
							"Path Changer",
							"The specified patht is not a directory!" );
					}
					else
					{
						changeActiveTo( foTo );
					}
				}
				catch (Exception e)
				{
					showError(
						"Path Changer Error",
						"There was an error changing to the specified path.",
						e );
				}
			}
		}
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see fileCommodore.plugin.Plugin#inactiveSelectionChanged()
	 */
	@Override
	public void inactiveSelectionChanged()
	{
		// TODO Auto-generated method stub
		
	}
	
}
